<title>菜单管理</title>

<div class="layui-card">
  <div class="layui-card-body">
    <ul id="treeDemo" class="ztree"></ul>
    <input id="select_menu_id" name="select_menu_id" type="hidden"/>
    <input id="select_menu_name" name="select_menu_name" type="hidden"/>
  </div>
</div>


<style>
  .ztree .node_name {
    font-style: normal;
    font-variant: normal;
    font-weight: normal;
    font-stretch: normal;
    font-size: 14px;
    font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 微软雅黑, Tahoma, Arial, sans-serif;
  }

  .ztree li {
    line-height: 28px;
  }

  .ztree li a {
    height: 28px;
    color: #666;
    font-weight: normal;
  }

  .ztree li a:hover {
    text-decoration: none;
    color: #FF5722;
  }

  .ztree li a.curSelectedNode {
    padding: 1px 3px 0 0;
    margin: 0;
    cursor: pointer;
    vertical-align: top;
    display: inline-block;
    height: 28px;
    border: none;
    background-color: #F0F0F0;
    color: #FF5722;
  }

  .ztree li.isLeaf {
    display: inline;
  }

  .ztree > li > ul > li > ul > li > ul {
    overflow: hidden;
  }

  .ztree > li > ul > li > ul > li > ul > li {
    float: left;
    width: 19%;
    box-sizing: border-box;
  }
</style>
<link rel="stylesheet" href="{{ADMIN_PATH}}layui/layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet" href="{{ADMIN_PATH}}layui/layuiadmin/style/admin.css" media="all">
<link rel="stylesheet" href="{{ADMIN_PATH}}ztree/css/zTreeStyle/zTreeStyle.css" media="all">
<script src="{{ADMIN_PATH}}layui/layuiadmin/layui/layui.js"></script>
<script src="{{ADMIN_PATH}}ztree/js/jquery-1.4.4.min.js"></script>
<script src="{{ADMIN_PATH}}ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="{{ADMIN_PATH}}ztree/js/jquery.ztree.excheck.js"></script>
<SCRIPT type="text/javascript">
    var post_url='{{url('admin/auth/manager/menu')}}';
    <!--
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {

            onCheck: zTreeOnCheck
        }
    };
    function zTreeOnCheck(event, treeId, treeNode) {

        var checked = treeNode.checked;

        //console.log((treeNode?treeNode.name:"root")+"===="+treeNode.id+"===" + "checked " +(checked?"true":"false"));
        // refreshLayers();
        // clearCheckedOldNodes();
        var zTree = $.fn.zTree.getZTreeObj("treeDemo", setting),
            nodes = zTree.getCheckedNodes();



        var mynodes=new Array();
        var s=0;
        for (var i=0, l=nodes.length; i<l; i++) {
            if(nodes[i].mid!=0){
                mynodes[s]=nodes[i].rule_id;
                s++;
            }

        }
        console.log(mynodes);
        //将所有选中ajax提交
        $.ajax({
            type: 'POST',
            url: post_url,
            data: {id:{{$id}},data:mynodes},
            async: false,
            dataType: 'json',
            success: function (data) {
                if(data.code==0){
                    //layer.msg(data.msg);
                }else{
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.msg("异常");
            }
        });




    };
    var zNodes ={!! $menu_list !!};
    var code;
    function setCheck() {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
            py = $("#py").attr("checked")? "p":"",
            sy = $("#sy").attr("checked")? "s":"",
            pn = $("#pn").attr("checked")? "p":"",
            sn = $("#sn").attr("checked")? "s":"",
            type = { "Y":py + sy, "N":pn + sn};
        zTree.setting.check.chkboxType = type;
        showCode('setting.check.chkboxType = { "Y" : "' + type.Y + '", "N" : "' + type.N + '" };');
    }
    function showCode(str) {
        if (!code) code = $("#code");
        code.empty();
        code.append("<li>"+str+"</li>");
    }

    $(document).ready(function(){
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        var treeId = "treeDemo";
        var    treeObj = $.fn.zTree.getZTreeObj(treeId);
        treeObj.expandAll(true);
    });
    //-->
</SCRIPT>
